using System;
using System.Drawing;
using System.Windows.Forms;

namespace SnakeGame
{
    public partial class PlayerNameInputForm : Form
    {
        private TextBox nameTextBox;
        private Button okButton;
        private Button cancelButton;
        private Label promptLabel;

        public string PlayerName => nameTextBox.Text.Trim();

        public PlayerNameInputForm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.promptLabel = new Label();
            this.nameTextBox = new TextBox();
            this.okButton = new Button();
            this.cancelButton = new Button();
            this.SuspendLayout();

            // promptLabel
            this.promptLabel.AutoSize = true;
            this.promptLabel.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
            this.promptLabel.Location = new Point(12, 20);
            this.promptLabel.Name = "promptLabel";
            this.promptLabel.Size = new Size(200, 20);
            this.promptLabel.Text = "恭喜！您的分数已进入排行榜！\n请输入您的姓名：";

            // nameTextBox
            this.nameTextBox.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
            this.nameTextBox.Location = new Point(12, 50);
            this.nameTextBox.Name = "nameTextBox";
            this.nameTextBox.Size = new Size(260, 25);
            this.nameTextBox.TabIndex = 0;
            this.nameTextBox.MaxLength = 20;
            this.nameTextBox.KeyPress += new KeyPressEventHandler(this.nameTextBox_KeyPress);

            // okButton
            this.okButton.BackColor = Color.LightGreen;
            this.okButton.FlatStyle = FlatStyle.Flat;
            this.okButton.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
            this.okButton.Location = new Point(12, 90);
            this.okButton.Name = "okButton";
            this.okButton.Size = new Size(80, 35);
            this.okButton.TabIndex = 1;
            this.okButton.Text = "确定";
            this.okButton.UseVisualStyleBackColor = false;
            this.okButton.Click += new EventHandler(this.okButton_Click);

            // cancelButton
            this.cancelButton.BackColor = Color.LightGray;
            this.cancelButton.FlatStyle = FlatStyle.Flat;
            this.cancelButton.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
            this.cancelButton.Location = new Point(100, 90);
            this.cancelButton.Name = "cancelButton";
            this.cancelButton.Size = new Size(80, 35);
            this.cancelButton.TabIndex = 2;
            this.cancelButton.Text = "取消";
            this.cancelButton.UseVisualStyleBackColor = false;
            this.cancelButton.Click += new EventHandler(this.cancelButton_Click);

            // PlayerNameInputForm
            this.AcceptButton = this.okButton;
            this.AutoScaleDimensions = new SizeF(8F, 15F);
            this.AutoScaleMode = AutoScaleMode.Font;
            this.CancelButton = this.cancelButton;
            this.ClientSize = new Size(284, 140);
            this.Controls.Add(this.cancelButton);
            this.Controls.Add(this.okButton);
            this.Controls.Add(this.nameTextBox);
            this.Controls.Add(this.promptLabel);
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "PlayerNameInputForm";
            this.StartPosition = FormStartPosition.CenterParent;
            this.Text = "输入姓名";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(PlayerName))
            {
                MessageBox.Show("请输入您的姓名！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                nameTextBox.Focus();
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void nameTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                okButton_Click(sender, e);
            }
        }
    }
} 